const config = require('../../../config/config.local');
const amazonMws = require('amazon-mws')(config.AWSAccessKeyId, config.AWSSecretKey);
const isProduction = process.env.NODE_ENV === 'production';

const listInventorySupply = {};
listInventorySupply.generateOption = function(seller_id, mws_auth_token, SellerSkuList=null, marketplaceId=null, responseGroup=null, queryStartDateTime=null){
  let baseOption = {
    'Version': '2010-10-01',
    'Action': 'ListInventorySupply',
    'SellerId': seller_id,
    'MWSAuthToken': mws_auth_token,
    // 'MarketplaceId': marketplaceId,
    // 'SellerSkus.member': '',
    // 'QueryStartDateTime': queryStartDateTime, //new Date(2016, 11, 24)
  };

  if (SellerSkuList) {
    let keyPrefix = "SellerSkus.member";
    SellerSkuList.forEach((item, index) => {
      baseOption[keyPrefix + "." + (index+1)] = item
    });
  }
  if (marketplaceId)
    baseOption['MarketplaceId'] = marketplaceId;
  if (responseGroup)
    baseOption['ResponseGroup'] = responseGroup;
  if (queryStartDateTime)
    baseOption['QueryStartDateTime'] = queryStartDateTime;
  return baseOption;
};

listInventorySupply._ = function(options) {
  if (!isProduction) {
    return amazonMws.fulfillmentInventory.search(options);
  } else {
    console.error("bot not implemented!");
  }
};

listInventorySupply.listInventorySupply = function(seller_id, mws_auth_token, SellerSkuList=null, marketplaceId=null, responseGroup=null, queryStartDateTime=null) {
  return this._(this.generateOption(seller_id, mws_auth_token, SellerSkuList, marketplaceId, responseGroup, queryStartDateTime));
};

module.exports = listInventorySupply;